package com.qixin.web.controller.System;

import com.qixin.api.bean.ComPeople;
import com.qixin.api.bean.ComPtUser;
import com.qixin.api.service.ComPeopleService;
import com.qixin.api.service.ComPtUserService;
import com.qixin.web.service.WeUserService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

/**
 * Created by Zhang on 2018/10/1.
 * 微信登陆 回调后台redirect_uri  控制层
 */
@Controller
@RequestMapping("/login_redirect")
public class WeChatLoginController {
    private static final Logger logger = LoggerFactory.getLogger(WeChatLoginController.class);
    @Autowired
    WeUserService weUserService;
    @Autowired
    ComPtUserService comPtUserService;
    @Autowired
    ComPeopleService comPeopleService;
    @RequestMapping("/getUserForWechat")
    public String weixinLogin(Model model,HttpServletRequest request, HttpServletResponse response, HttpSession session ) throws Exception {
        weUserService.weixinLogin(request,response,session);
        ComPtUser comPtUser =new ComPtUser();
        ComPeople comPeople=new ComPeople();
        if(session.getAttribute("people_user")!=null){
            comPeople=comPeopleService.selectById(((ComPeople)session.getAttribute("people_user")).getId());
            model.addAttribute("peopleUser",comPeople);
        }else {
            if(session.getAttribute("pt_user")!=null){
                comPtUser=comPtUserService.selectById(((ComPtUser)session.getAttribute("pt_user")).getId());
                model.addAttribute("ptUser",comPtUser);
            }
        }
        return "System/UserInfo" ;
    }


}
